import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:super_person_app/utils/storage.dart';
import 'package:timeago/timeago.dart';

import 'global_bindings.dart';

class Service {
  // 是否登录过，用于免登录
  static late bool isLogin = false;
  static const String SERVER_API_URL = "http://law.291w.com/law/app";
  // 是否启用缓存
  static const bool CACHE_ENABLE = false;

  static Future init() async {
    // 运行初始
    WidgetsFlutterBinding.ensureInitialized();
    GlobalBindings().dependencies();

    /// 初始持久化数据
    await JSpUtil.getInstance();

    String? accessToken = JSpUtil.getString("access_token");
    if (accessToken!.isNotEmpty) {
      isLogin = true;
    } else {
      isLogin = false;
    }

    setLocaleMessages('zh', ZhMessages());

    // android 状态栏为透明的沉浸
    if (Platform.isAndroid) {
      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
          statusBarColor: Colors.transparent,
          statusBarBrightness: Brightness.light,
          systemNavigationBarColor: Color(0xffFAFAFA),
          statusBarIconBrightness: Brightness.dark);
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }
}
